--[[
    函数：lua3_lab_get_industry_color
    功能：获取“行业－颜色”的映射表
    返回：返回数组：
            0:code,0表示成功，其它表示没搜索到结果中途退出
            1:industry_colors,“行业－颜色”映射表，格式："[ [行业ID,颜色ID,颜色ID] ]", 形如："[ [1,11,12] ]"
--]]

-- ########################################################

-- 分类的前缀
local PREFIX_TYPE = "lab_type_"
-- 标签的前缀
local PREFIX_LABEL_INDUSTRY = "lab_label_industry_"
local PREFIX_LABEL_SCENE = "lab_label_scene_"
local PREFIX_LABEL_STYLE = "lab_label_style_"
local PREFIX_LABEL_COLOR = "lab_label_color_"
local PREFIX_LABEL_CUSTOM = "lab_label_custom_"
local PREFIX_PRODUCT = "lab_product_"
local PREFIX_LABEL_INDUSTRY_COLOR = "lab_label_ind_color_"

-- 排序的key
local KEY_SORT = "lab_sort"
-- ID-模版缓存的前缀
local PREFIX_DESIGN = "lab_d_"

-- key的连接符号
local PREFIX_S = "*"
-- 数组字符串的分割符号
local PREFIX_ARRAY_SPLIT = ","
-- 左括号
local PREFIX_LEFT_EM = "["
-- 右括号
local PREFIX_RIGHT_EM = "]"

-- product的hash表的几个filed名称
local PRODUCT_HASH_KEY_FILED_LOGO_IMG = "logo_img"
local PRODUCT_HASH_KEY_FILED_SWITCH_LIST = "switch_list"
local PRODUCT_HASH_KEY_FILED_SEL_CONTENT_ID = "sel_content_id"


-- ########################################################
-- [局部函数] 组成返回值数组，第0个是错误码，第1个是ids
local retData = function(code,industry_colors)
    local ret = {}
    table.insert(ret, code)

    table.insert(ret, industry_colors)

    return ret
end


-- ########################################################


-- “行业－颜色”映射表
local ret = '';
ret = ret..PREFIX_LEFT_EM

local len_prefix_industry_color = #PREFIX_LABEL_INDUSTRY_COLOR
local key = PREFIX_LABEL_INDUSTRY_COLOR..PREFIX_S
local ic_keys = redis.call('keys',key)
local ic_len = #ic_keys
for i= 1, ic_len do
    -- 添加外层分隔符
    if(i>1)
    then
        ret = ret..PREFIX_ARRAY_SPLIT
    end

    -- 添加内层左括号
    ret = ret..PREFIX_LEFT_EM

    -- 记录行业id到第0个位置
    local key1 = ic_keys[i]
    local id_industry = string.sub(key1,len_prefix_industry_color+1)
    ret = ret..id_industry

    --  遍历颜色id
    local colors = redis.call('smembers',key1)
    local c_len = #colors
    for j=1, c_len do
        -- 添加分隔符
        ret = ret..PREFIX_ARRAY_SPLIT

        -- 添加颜色
        local id_color = colors[j]
        ret = ret..id_color
    end

    -- 添加内层右括号
    ret = ret..PREFIX_RIGHT_EM
end
ret = ret..PREFIX_RIGHT_EM


--  返回
return retData(0,ret)
-- ########################################################
